<?php
/**
 * @Name: DepartmentSearch.php
 * @Author: yashuai
 */

namespace App\Http\Search\Org;


use App\Http\Model\ConstCode;
use App\Http\Model\Org\DepartmentModel;
use App\Http\Search\BaseSearch;
use HugCode\PhpUnits\Utils\UtilArray;

class DepartmentSearch extends BaseSearch
{

    /**
     * @Desc 部门列表
     * @return array
     * @author yashuai
     */
    public function index()
    {
        $where  = [
            'Status' => ConstCode::BASIC_STATUS_NORMAL,
        ];
        $select = ['DepartmentID', 'Name', 'ParentID', 'PeopleNum', 'MasterID'];
        $list   = DepartmentModel::query()->where($where)
            ->select($select)
            ->orderBy('Order', 'DESC')
            ->get()->keyBy('DepartmentID')->toArray();
        return UtilArray::listToTree($list, 'DepartmentID', 'ParentID', 'children');
    }

}
